package cn.itsource.system.service.impl;

import cn.itsource.basic.util.PageList;
import cn.itsource.system.domain.DictionaryDetail;
import cn.itsource.system.mapper.DictionaryDetailMapper;
import cn.itsource.system.query.DictionaryDetailQuery;
import cn.itsource.system.service.IDictionaryDetailService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DictionaryDetailServiceImpl implements IDictionaryDetailService {

    @Autowired
    private DictionaryDetailMapper dictionaryDetailMapper;

    @Override
    @Transactional
    public void add(DictionaryDetail dictionaryDetail) {
        dictionaryDetailMapper.save(dictionaryDetail);
    }

    @Override
    @Transactional
    public void update(DictionaryDetail dictionaryDetail) {
        dictionaryDetailMapper.update(dictionaryDetail);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        dictionaryDetailMapper.delete(id);
    }

    @Override
    public DictionaryDetail queryById(long id) {
        return dictionaryDetailMapper.loadById(id);
    }

    @Override
    public List<DictionaryDetail> queryAll() {
        return dictionaryDetailMapper.loadAll();
    }

    @Override
    public PageList<DictionaryDetail> queryPage(DictionaryDetailQuery detailQuery) {
        Integer total = dictionaryDetailMapper.queryCount(detailQuery);
        if(total == 0){
            return new PageList<>();
        }else {
            List<DictionaryDetail> list = dictionaryDetailMapper.queryData(detailQuery);
            return new PageList<>(total,list);
        }
    }
}
